
#include <stdlib.h>
#include "sba/eucsbademo.h"
#include "sba/readparams.h"

int main(int argc, char *argv[])
{
int cnp=6, /* 3 rot params + 3 trans params */
    pnp=3, /* euclidean 3D points */
    mnp=2; /* image points are 2D */

  if(argc!=3 && argc!=4){
    fprintf(stderr, "Usage is %s <camera params> <point params> [<intrinsic calibration params>]\n", argv[0]);
    exit(1);
  }

  if(argc==4){ /* fixed intrinsics */
    fprintf(stderr, "Starting BA with fixed intrinsic parameters\n");
    sba_driver(argv[1], argv[2], argv[3], cnp, pnp, mnp, quat2vec, vec2quat, cnp+1, "-", "-");
  }
  else{
    cnp+=5; /* 5 more params for calibration */
    if(readNumParams(argv[1])-1==cnp+5){ /* with distortion */
      cnp+=5; /* 5 more params for distortion */
      fprintf(stderr, "Starting BA with varying intrinsic parameters & distortion\n");
      sba_driver(argv[1], argv[2], NULL, cnp, pnp, mnp, quat2vec, vec2quat, cnp+1, "-", "-");
    }
    else{
      fprintf(stderr, "Starting BA with varying intrinsic parameters\n");
      sba_driver(argv[1], argv[2], NULL, cnp, pnp, mnp, quat2vec, vec2quat, cnp+1, "-", "-");
    }
  }

  return 0;
}
